package orm

import (
	"fmt"
	"gitee.com/dreamwood/ez"
)

func (this *QueryBuilder) CreateOrders() {
	//var orderSlice = make([]string, 0)
	if this.Order != nil {
		//逐层剥离
		for _, order := range this.Order {
			order = ez.SnakeString(order)
			//key:=order
			if order[0:1] == "-" {
				//key:=order[1:]
				//orderSlice = append(orderSlice, fmt.Sprintf("%s DESC", order[1:]))
				as, f := this.getJoinAlis(order[1:])
				if as != "" {
					this.Tx.Order(fmt.Sprintf("%s.%s DESC", as, f))
				} else {
					this.Tx.Order(fmt.Sprintf("%s DESC", f))
				}
			} else {
				//orderSlice = append(orderSlice, fmt.Sprintf("%s ASC", order))
				as, f := this.getJoinAlis(order)
				//this.Tx.Order(fmt.Sprintf("%s.%s ASC", as,f))
				if as != "" {
					this.Tx.Order(fmt.Sprintf("%s.%s ASC", as, f))
				} else {
					this.Tx.Order(fmt.Sprintf("%s ASC", f))
				}
			}
		}
	}
	//return strings.Join(orderSlice, ",")
}
